package jehc.djshi.log.web;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jehc.djshi.common.annotation.NeedLoginUnAuth;
import jehc.djshi.common.base.BaseAction;
import jehc.djshi.common.base.BasePage;
import jehc.djshi.common.base.BaseResult;
import jehc.djshi.common.base.BaseSearch;
import jehc.djshi.common.util.StringUtil;
import jehc.djshi.log.model.XtModifyRecord;
import jehc.djshi.log.service.XtModifyRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;

/**
 * @Desc 修改记录日志
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@RestController
@RequestMapping("/xtModifyRecord")
@Api(value = "修改记录日志API",description = "修改记录日志API")
public class XtModifyRecordController extends BaseAction {
	@Autowired
	private XtModifyRecordService xtModifyRecordService;
	/**
	* 加载初始化列表数据并分页
	* @param baseSearch
	*/
	@NeedLoginUnAuth
	@PostMapping(value="/list")
	@ApiOperation(value="查询修改记录日志列表并分页", notes="查询修改记录日志列表并分页")
	public BasePage getXtModifyRecordListByCondition(@RequestBody(required=true)BaseSearch baseSearch){
		Map<String, Object> condition = baseSearch.convert();
		commonHPager(baseSearch);
		List<XtModifyRecord> xt_Modify_RecordList = xtModifyRecordService.getXtModifyRecordListByCondition(condition);
		PageInfo<XtModifyRecord> page = new PageInfo<XtModifyRecord>(xt_Modify_RecordList);
		return outPageBootStr(page,baseSearch);
	}
	/**
	* 获取对象
	* @param xt_modify_record_id
	*/
	@NeedLoginUnAuth
	@GetMapping(value="/get/{xt_modify_record_id}")
	@ApiOperation(value="查询单个修改记录日志", notes="查询单个修改记录日志")
	public BaseResult getXtModifyRecordById(@PathVariable("xt_modify_record_id")String xt_modify_record_id){
		XtModifyRecord xt_Modify_Record = xtModifyRecordService.getXtModifyRecordById(xt_modify_record_id);
		return outDataStr(xt_Modify_Record);
	}
	/**
	* 添加
	* @param xtModifyRecord
	*/
	@PostMapping(value="/add")
	@ApiOperation(value="创建单个修改记录日志", notes="创建单个修改记录日志")
	public BaseResult addXtModifyRecord(@RequestBody XtModifyRecord xtModifyRecord){
		int i = 0;
		if(null != xtModifyRecord){
			xtModifyRecord.setXt_modify_record_id(toUUID());
			i=xtModifyRecordService.addXtModifyRecord(xtModifyRecord);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
	/**
	* 修改
	* @param xtModifyRecord
	*/
	@PutMapping(value="/update")
	@ApiOperation(value="编辑单个修改记录日志", notes="编辑单个修改记录日志")
	public BaseResult updateXtModifyRecord(@RequestBody XtModifyRecord xtModifyRecord){
		int i = 0;
		if(null != xtModifyRecord){
			i=xtModifyRecordService.updateXtModifyRecord(xtModifyRecord);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
	/**
	* 删除
	* @param xt_modify_record_id
	*/
	@DeleteMapping(value="/delete")
	@ApiOperation(value="删除修改记录日志", notes="删除修改记录日志")
	public BaseResult delXtModifyRecord(String xt_modify_record_id){
		int i = 0;
		if(!StringUtil.isEmpty(xt_modify_record_id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("xt_modify_record_id",xt_modify_record_id.split(","));
			i=xtModifyRecordService.delXtModifyRecord(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
}
